import os
import threading

from event.event_bus import event_bus


class parser(object):
    def __init__(self):
        pass

    def take_action(self,command,type,action,tips):
        return_tips = tips
        if type == "excel":
            self._cmd(action)
        elif type == "display_in_chat":
            return_tips = action
        elif type == "directory":
            self._cmd("start explorer %s" % action)
        elif type == "web":
            self._cmd("start explorer %s" % action)
        elif type == "assist": #助理命令
            if command == "退出":
                event_bus().post(type=type,msg=command)

        return return_tips

    def _cmd(self, str):
        thrd_once = threading.Thread(target=self._cmd_thread, args=(str,))
        thrd_once.start()

    def _cmd_thread(self, str):
        os.system(str)